<?php
    require_once("include/common.php");

    $uid = $_GET['uid'] ?? '' ;
?>

<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1, maximum-scale=1">

<title>修改口令</title>

    <?php
        require_once("pages/resources.php");
    ?>
 
    <script src="/meter/resources/jquery/jquery-2.0.3.js"></script>
    
    <script src="/meter/resources/js-base-util.js"></script>
    <script type="text/javascript" src="/meter/resources/layer/layer.js"></script>
   
</head>
<body  id="deviceCtrl" >

  
    <!-- Page container -->
    <div class="page-container">

                 
             
        <!-- Form begin -->
        <form class="form-horizontal" role="form" >
            <div class="panel panel-default">
                
                <div class="panel-body">
               
                    <div class="form-group  ">
                        <label class="col-sm-2 control-label"> 账号  :</label>
                        <div class="col-sm-4">
                            <input type="text" name="uid" class="form-control" id="_INPUT_USERID" value="<?=$uid?>"  
                             readonly="" 
                             >  
                        </div>
                    </div>
                    <div class="form-group ">
                        <label class="col-sm-2 control-label"> Old Password :</label>
                            <div class="col-sm-4">
                                <input type="password" class="form-control" id="_INPUT_OLDPASS" value="" >  
                            </div>
                    </div>
                    <div class="form-group  ">
                        <label class="col-sm-2 control-label"> Password1 :</label>
                            <div class="col-sm-4">
                                <input type="password" class="form-control" id="_INPUT_PASS1" value="" >  
                            </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label"> Password2:  </label>
                        <div class="col-sm-4">
                                <input type="password" class="form-control" id="_INPUT_PASS2" value="" >  
                        </div>
                    </div>  

                       

                    <div class="form-actions text-right">
                        <input type="button" value="Save" onclick="passwd();"  class="btn btn-primary">
                    </div>

                </div>
            </div>
        </form>
                                     
    

</body>
<script type="text/javascript">
 
 

    function passwd() {

        var uid = $('#_INPUT_USERID').val();
        var old = $('#_INPUT_OLDPASS').val();
        var pass1 = $('#_INPUT_PASS1').val();
        var pass2 = $('#_INPUT_PASS2').val();

        if (! uid ) {
            layer.tips('账号不能为空' , '#_INPUT_USERID' ,{
                    tips: 3
                });
            return ;
        }

        if (! old ) {
            layer.tips(' 原始口令 不能为空' , '#_INPUT_OLDPASS' ,{
                   tips: 3
                });
            return ;
        }
        if (! pass1 ) {
            layer.tips(' 口令1 不能为空' , '#_INPUT_PASS1' ,{
                   tips: 3
                });
            return ;
        }
        if (! pass2 ) {
            layer.tips(' 口令2 不能为空' , '#_INPUT_PASS2' ,{
                   tips: 3
                });
            return ;
        }    

        if ( pass1 != pass2 ) {
            layer.tips(' 两次输入口令不一致 ' , '#_INPUT_PASS1' ,{
                   tips: 3
                });
            return ;
        }    
        var url = '/meter/rest/disp.php?m=account_passwd'  ;
        $.post( url ,
                {
                    "uid" : uid , 
                    "passwd" : old , 
                    "newpasswd" : pass1  
                } ,function (response) {
                response_status( 'passwd user :' + uid  ,  response ); 
                if (response.status != 0) {
                    layer.alert('错误 :' + response.message , {
                      icon: 2,
                      // skin: 'layer-ext-moon' //该皮肤由layer.seaning.com友情扩展。关于皮肤的扩展规则，去这里查阅
                    });
                }else {
                    layer.msg('密码修改成功' ,{
                        time: 2000
                    } , function(){
                        var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                        if( parent && parent.layer )
                            parent.layer.close(index);
                    });

                }   
        }

        );

        return false;
    }  
          
        

      
    function response_status( command , result ){
        if(result.status == 0 ){
            $('#responseId').removeClass('label-warning');
            $('#responseId').addClass('label-success');
            $('#responseId').text( 'success! ' + command);
        }else {
            $('#responseId').removeClass('label-success');
            $('#responseId').addClass('label-warning');
            
            $('#responseId').text( 'Error : ' + result.status + ' ' + result.message + '\n' + command );
        }
    }
    
     

</script>
</html>
